package com.kaifamiao.list;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * 4、ArrayList的 iterator 和 listIterator 方法返回的迭代器是 "快速失败"(fail-fast)的
 */
public class ArrayListTest2 {

    public static void main(String[] args) {

        Collection<String> coll = List.of("熊大","熊二","光头强","涂涂","翠花","吉吉国王","毛毛");

        ArrayList<String> list = new ArrayList<>( coll );

        System.out.println( list );

        Iterator<String> it = list.iterator();
        while( it.hasNext() ) {
            String name = it.next();
            if( "光头强".equals( name ) ) {
                // it.remove(); // 建议使用的操作方法
                list.remove( "光头强" ); // ConcurrentModificationException
            }
        }

        System.out.println( list );

    }

}
